home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1995.rar
/
1995
/
JUN
/
CA9506
/
ca_list.txt
Wrap
Text File
|
1995-05-09
|
10KB
|
446 lines
***************************************************************
Begin Listing 1 -- Complete VB Code for Project
***************************************************************
Begin Form Form1
Caption = "Form1"
ClientHeight = 3825
ClientLeft = 1095
ClientTop = 1485
ClientWidth = 3555
Height = 4230
Left = 1035
LinkTopic = "Form1"
ScaleHeight = 3825
ScaleWidth = 3555
Top = 1140
Width = 3675
Begin CommandButton Command4
Caption = "Control 1"
Height = 495
Index = 1
Left = 240
TabIndex = 5
Top = 2280
Width = 1215
End
Begin CommandButton Command4
Caption = "Control 0"
Height = 495
Index = 0
Left = 240
TabIndex = 4
Top = 1800
Width = 1215
End
Begin CommandButton Command3
Caption = "Case"
Height = 495
Left = 240
TabIndex = 3
Top = 1080
Width = 1215
End
Begin TextBox Text1
Height = 3615
Left = 1560
MultiLine = -1 'True
TabIndex = 2
Text = "Text1"
Top = 120
Width = 1935
End
Begin CommandButton Command2
Caption = "Loop2"
Height = 495
Left = 240
TabIndex = 1
Top = 600
Width = 1215
End
Begin CommandButton Command1
Caption = "Loop1"
Height = 495
Left = 240
TabIndex = 0
Top = 120
Width = 1215
End
Begin Label Label1
BorderStyle = 1 'Fixed Single
Caption = "Control Status"
Height = 615
Left = 240
TabIndex = 6
Top = 2880
Width = 1215
End
End
Sub CaseTest ()
Dim NumToTest As Integer
Dim Msg As String
Dim Title As String
Msg = "Enter a value between 1 and 10."
Title = "CaseTest"
Do
NumToTest = InputBox(Msg, Title, "1")
Loop Until NumToTest >= 1 And NumToTest <= 10
MsgBox "You entered " & NumToTest ' Display message.
Select Case NumToTest
Case 1, 3, 5, 7, 9: Msg = "odd number"
Case 2, 4, 6, 8, 10: Msg = "even number"
End Select
MsgBox Msg
End Sub
Sub Command1_Click ()
Loop1
End Sub
Sub Command2_Click ()
Loop2
End Sub
Sub Command3_Click ()
CaseTest
End Sub
Sub Command4_Click (Index As Integer)
If Index = 0 Then
Label1.Caption = "Control array 0 pressed."
Else
Label1.Caption = "Control array 1 pressed."
End If
End Sub
Sub Loop1 ()
Dim I As Integer
Dim J As Integer
Static TestArray(10, 10)
For I = 1 To 10
For J = 1 To 10
TestArray(I, J) = I
Next J
Next I
MsgBox "Test Array 10x10 filled."
End Sub
Sub Loop2 ()
Dim Dice1 As Integer
Dim Flag As Integer
Randomize
Text1.Text = "Tossing"
Flag = 77
While Flag = 77
Dice1 = Int(6 * Rnd + 1)
If Dice1 < 6 Then
Text1.Text = Text1.Text & Str(Dice1)
Else
Text1.Text = Text1.Text & Str(Dice1) & " !Bingo!"
Flag = 1
End If
Wend
End Sub
***************************************************************
End Listing 1
***************************************************************
***************************************************************
Begin Listing 2 -- Code produced by Conversion Assistant
***************************************************************
unit loops2;
{ Delphi Project translation }
{ From EarthTrek Inc. }
interface
uses VB,
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
{ append modal form names here }
type
TForm1 = class(TForm)
Command4IndeX1: TButton;
Command4IndeX0: TButton;
Command3: TButton;
Text1: TEdit;
Command2: TButton;
Command1: TButton;
Label1: TLabel;
procedure Command1_Click(Sender: TObject);
procedure Command2_Click(Sender: TObject);
procedure Command3_Click(Sender: TObject);
procedure Command4_Click(Sender: TObject);
{ Array function helpers }
function Command4(ind: integer): TButton;
private
{ Private declarations }
public
{ Public declarations }
procedure CaseTest;
procedure Loop1;
procedure Loop2;
end;
var
iForm1: TForm1;
implementation
{$R *.DFM}
{----------------------------------------}
{ Array function helpers - code body }
function TForm1.Command4(ind: integer): TButton;
begin
result := TButton(FindComponent('Command4IndeX'+VBstr(ind)));
end;
{----------------------------------------}
procedure TForm1.CaseTest;
Var
NumToTest: integer;
Msg: string;
Title: string;
begin
( )
Msg := 'Enter a value between 1 and 10.';
Title := 'CaseTest';
Do;
NumToTest := InputBox(Msg, Title, '1');
Loop Until NumToTest >= 1 And NumToTest <= 10;
MsgBox 'You entered ' + NumToTest { Display message.};
case NumToTest of
1: begin;
end;
2: begin;
end;
end; {c a s e}
MsgBox Msg;
end;
{----------------------------------------}
procedure TForm1.Command1_Click(Sender: TObject);
begin
Loop1;
end;
{----------------------------------------}
procedure TForm1.Command2_Click(Sender: TObject);
begin
Loop2;
end;
{----------------------------------------}
procedure TForm1.Command3_Click(Sender: TObject);
begin
CaseTest;
end;
{----------------------------------------}
procedure TForm1.Command4_Click(Sender: TObject);
begin
If VBIndex(Sender) = 0 Then
begin
Label1.Caption := 'Control array 0 pressed.';
end
else
begin
Label1.Caption := 'Control array 1 pressed.';
end;
end;
{----------------------------------------}
procedure TForm1.Loop1;
Var
I: integer;
J: integer;
begin
Static TestArray(10, 10);
For I := 1 To 10 do
begin
For J := 1 To 10 do
begin
TestArray(I, J) := I;
end;
end;
MsgBox 'Test Array 10x10 filled.';
end;
{----------------------------------------}
procedure TForm1.Loop2;
Var
Dice1: integer;
Flag: integer;
begin
Randomize;
Text1.Text := 'Tossing';
Flag := 77;
While Flag = 77;
Dice1 := Int(6 * Rnd + 1);
If Dice1 < 6 Then
begin
Text1.Text := Text1.Text + VBstr(Dice1);
end
else
begin
Text1.Text := Text1.Text + VBstr(Dice1) + ' i.iBingo.';
Flag := 1;
end;
Wend;
end;
begin
RegisterClasses( [TForm1,TButton,TEdit,TLabel] );
iForm1 := TForm1.Create(Application);
end.
***************************************************************
End Listing 2
***************************************************************
***************************************************************
Begin Listing 3 -- Corrected Code
***************************************************************
unit loops2;
{ GaryÆs translation of }
{ Delphi Project translation }
{ From EarthTrek Inc. }
interface
uses VB,
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
{ append modal form names here }
type
TForm1 = class(TForm)
Command4IndeX1: TButton;
Command4IndeX0: TButton;
Command3: TButton;
Command2: TButton;
Command1: TButton;
Label1: TLabel;
Memo1: TMemo;
procedure Command1_Click(Sender: TObject);
procedure Command2_Click(Sender: TObject);
procedure Command3_Click(Sender: TObject);
procedure Command4_Click(Sender: TObject);
{ Array function helpers }
function Command4(ind: integer): TButton;
private
{ Private declarations }
public
{ Public declarations }
procedure CaseTest;
procedure Loop1;
procedure Loop2;
end;
var
iForm1: TForm1;
implementation
{$R *.DFM}
{----------------------------------------}
{ Array function helpers - code body }
function TForm1.Command4(ind: integer): TButton;
begin
result := TButton(FindComponent('Command4IndeX'+VBstr(ind)));
end;
{----------------------------------------}
procedure TForm1.CaseTest;
Var
NumToTest: Integer;
StrNum : String;
Msg: string;
Title: string;
Code: Integer;
begin
Msg := 'Enter a value between 1 and 10.';
Title := 'CaseTest';
Repeat
StrNum := InputBox(Msg, Title, '1');
Val(StrNum,NumToTest,Code);
Until (NumToTest >= 1) And (NumTotest <= 10);
ShowMessage('You entered ' + StrNum); { Dis